/*
 * @Descripttion: 
 * @version: 
 * @Author: cyj
 * @Date: 2023-03-20 20:07:11
 */
import Mock from 'mockjs'
import myfirend from './myfirend'
import ismyfirend from '@/mock/ismyfirend'
import message from '@/mock/message'
import {
  setItem,
  getItem
} from '@/utils/utils'

//返回模拟用户列表
Mock.mock('/mock/firendlist', 'get', () => {
  return {
    status: 200,
    data: myfirend
  }
})
//返回用户1的好友列表
Mock.mock('/mock/ismyfirend', 'get', {
  status: 200,
  data: ismyfirend
})

//返回聊天记录
Mock.mock('/mock/chat', 'get', () => {
  // console.log('message', message);
  let msgList = getItem('main') || []
  // console.log(msgList);
  if (Object.keys(msgList).length == 0) { //如果本地存储没有存储
    return {
      status: 200,
      message: 'success',
      data: message
    }
  } else {
    return {
      status: 200,
      message: 'success',
      data: msgList.messageList
    }
  }

})

//添加新聊天消息
Mock.mock('/mock/addmsg', 'post', (data) => {
  let {
    body
  } = data
  // console.log(body);
  let msgList = getItem('main') //从本地存储中获取数据
  // console.log(msgList);
  msgList.messageList.unshift(JSON.parse(body)) //添加到本地存储中
  // console.log(msgList.messageList);
  setItem('main', msgList)
  return {
    code: 200,
    message: 'success'
  }
})
